define(function(require, exports, module) {
    'use strict';
    
    var rk = require('rk');
    require('../../su/xsySuRefer/widget');

    $.widget('rk.xsyCustomizeRefer', $.rk.xsySuRefer, {
        options: {
            iconClass: 'xsy_su_refer_customize_icon',
            business: 'customize',
            createAct: 'createCustomize'
        },
        _create: function(){
            var me = this;
            var elem = me.element;
            var opt = me.options;

            me._super();

            me._reload();
        },
        _reload:function(){ 
            var me = this;
            var elem = me.element;
            var opt = me.options;

            var fromBelongId = opt.parentEntityId;
            var fromDataId = me._getDetailId();
            var fromItemId = opt.referItemId;

            var config = {
                iconClass: opt.iconClass,
                linkOfFinal: '/final/customize.action?id={{id}}&belongId={{belongId}}',
                linkOfMore: '/customize.action?belongId=' + opt.childEntityId + '&fromBelongId=' + fromBelongId + "&fromDataId=" + fromDataId + "&fromItemId=" + fromItemId,
                buttons: ['create'],
                children: [
                    {   
                        type: 'card'
                    },
                    {   
                        type: 'grid'
                    }
                ],
                isFold: false
            };
            

            me._loadData({}, function (result){
                /*if(me.data_bound){
                    me.bindData(result.self);
                }else{
                    me._render(config, result);
                }*/
                me._render(config, result);
            });
        },
        _delete: function(celldata){
            var me = this;
            var elem = me.element;
            var opt = me.options;
           

            var businessData = {};
            businessData.validateUrl = '/json/crm_customize/validate-delete.action';
            businessData.url = '/json/crm_customize/delete.action';
            businessData.postJson = {
                customizeIds : celldata.id,
                belongId : celldata.belongId
            }
            businessData.confirmTip = function(json){
                var html = "";
                if(json.status == 200001){
                    html = json.data;
                }else{
                    var html_substr = celldata.config.title + '【' + celldata.name + '】';
                    html = rk.i18n('ACCOUNT_DELETE_ARRAY_STRING_1', html_substr);
                }
                return html;
            }

            me.do_cascadeDelete(celldata, businessData)

        }
    });
});